/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain;

import domain.exceptions.*;

import java.io.IOException;
import java.util.Iterator;
import astar.CreateGraph;
import presentation.Client;
import presentation.Mymain;

/**
 *
 * @author shaigi
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws CannotPlaceAgentHereException {
    	
    	String 	assinment 		  = "2.1";//args[0];
    	Board 	board 			  = null;
    	boolean deterministicMode = false;
    	boolean zeroSumMode		  = false;
    	int		arsenal			  = 0;
    	
    	System.out.println("Ass: " + assinment);
        /**
         * Initlization
         */
    	//Scanner reader=new Scanner(System.in);
    	//int numberOfAgents;
        
        new Thread(new Runnable(){

			public void run() {
				try {
					Mymain.main(null);
					System.out.println("Server started from domain.Main");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
        	
        }).start();
        
    	// initialize game (but without agents yet):
        /************* For Assignment 1 *************/
        ///* 
        if (assinment.equals("1")){
	        board 				= new Board("board_Ass1.txt");
	        deterministicMode 	= true;
	        zeroSumMode 		= false;
	        arsenal 			= 0;	// It doesn't matter in assignment 1
        }
        //*/
        
        
        /************* For Assignment 2 *************/
        // 1. Deterministic zero-sum, optimal agent using mini-max with alph-beta pruning:
        ///*
        if (assinment.equals("2.1")){
	        board 				= new Board("board_Ass2.1.txt");
	        deterministicMode 	= true;
	        zeroSumMode 		= true;
	        arsenal				= 3;
        }
        //*/
        
        // 2. Deterministic non-zero-sum, optimal agent using maxi-max with alph-beta pruning:
        if (assinment.equals("2.2")){
        	board 				= new Board("board.txt");
        	deterministicMode 	= true;
        	zeroSumMode 		= false;
        	arsenal				= 3;
        }
        
        // 3. Non-Deterministic zero-sum, optimal agent using expecti-mini-max with alph-beta pruning:
        if (assinment.equals("2.3")){
        	board 				= new Board("board.txt");
        	deterministicMode 	= false;
        	zeroSumMode 		= true;
        	arsenal				= 3;
        }
        
        Game game = new Game(board, deterministicMode, zeroSumMode, arsenal, assinment);
        
        // initialize gui:
        Client c = new Client(game);
        
        game.initialize();
        
        // subscribe client for all agents:
        for (Iterator<Agent> it = game.getAgents().iterator(); it.hasNext();) {
            Agent agent = it.next();
            agent.subscribe(c);
        }
        game.placeAgents();
        
        //TODO: REMOVE FOLLOWING LINES!!!
        //CreateGraph graph=new CreateGraph(board,board.getNumberOfColumns()*board.getNumberOfRows());
        //System.out.println("printing graph from main with the location 114");
        //graph.findShortestDistanceToFlag(114);
        
        game.start();
        
    }

}
